{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b2701d33-f3ee-4530-bb78-fad38a5bb25c",
   "metadata": {},
   "source": [
    "# 第四节、数据选取"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f8d07e23-ed2f-49b2-a1d3-e685d0a13e78",
   "metadata": {},
   "source": [
    "## （1）字段数据"
   ]
  },
  {
   "cell_type": "code",
   "id": "04964ca6-08ea-43cc-943e-bdbed1ea9e13",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:56.788504Z",
     "start_time": "2025-06-20T05:46:56.781729Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "id": "7fbbc70f-74d3-4fd2-9ae6-fd8a74ec9838",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:56.953050Z",
     "start_time": "2025-06-20T05:46:56.932445Z"
    }
   },
   "source": [
    "df = pd.DataFrame(\n",
    "    data=np.random.randint(0, 150, size=(150, 3)),  # 计算机科目考试\n",
    "    columns=['Python','Tensorflow','Keras']\n",
    ")\n",
    "\n",
    "df.head()"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "0     107         108     30\n",
       "1     144          86     32\n",
       "2      75          89     86\n",
       "3      12          18     92\n",
       "4      39         110     71"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>108</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>144</td>\n",
       "      <td>86</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>75</td>\n",
       "      <td>89</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>18</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "      <td>110</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "id": "461a34c0-af88-4e44-8c79-3af1d99d56c6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:56.995656Z",
     "start_time": "2025-06-20T05:46:56.987917Z"
    }
   },
   "source": [
    "# 获取某一列，方式一\n",
    "df['Python']  # 返回Series对象"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      107\n",
       "1      144\n",
       "2       75\n",
       "3       12\n",
       "4       39\n",
       "      ... \n",
       "145     93\n",
       "146     50\n",
       "147     84\n",
       "148     83\n",
       "149      9\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "id": "75dda3dd-71f8-4fbc-aa15-898a6323314a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.100993Z",
     "start_time": "2025-06-20T05:46:57.094595Z"
    }
   },
   "source": [
    "# 获取某一列，方式二\n",
    "df.Python"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      107\n",
       "1      144\n",
       "2       75\n",
       "3       12\n",
       "4       39\n",
       "      ... \n",
       "145     93\n",
       "146     50\n",
       "147     84\n",
       "148     83\n",
       "149      9\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "id": "e1601667-a066-49b6-a601-5a2034879a7b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.153020Z",
     "start_time": "2025-06-20T05:46:57.144872Z"
    }
   },
   "source": [
    "# 获取某一列，方式三\n",
    "df.loc[:,'Python']"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      107\n",
       "1      144\n",
       "2       75\n",
       "3       12\n",
       "4       39\n",
       "      ... \n",
       "145     93\n",
       "146     50\n",
       "147     84\n",
       "148     83\n",
       "149      9\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 5
  },
  {
   "cell_type": "code",
   "id": "ce839db4-42ae-472b-9248-d51b52f60f09",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.213241Z",
     "start_time": "2025-06-20T05:46:57.206333Z"
    }
   },
   "source": [
    "# 获取某一列，方式四\n",
    "df.iloc[:, 0]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      107\n",
       "1      144\n",
       "2       75\n",
       "3       12\n",
       "4       39\n",
       "      ... \n",
       "145     93\n",
       "146     50\n",
       "147     84\n",
       "148     83\n",
       "149      9\n",
       "Name: Python, Length: 150, dtype: int32"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 6
  },
  {
   "cell_type": "code",
   "id": "ef150c3d-8101-427f-829e-eb71f150e167",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.251518Z",
     "start_time": "2025-06-20T05:46:57.242747Z"
    }
   },
   "source": [
    "# 获取某一列，返回DataFrame数据\n",
    "df[['Python']]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     Python\n",
       "0       107\n",
       "1       144\n",
       "2        75\n",
       "3        12\n",
       "4        39\n",
       "..      ...\n",
       "145      93\n",
       "146      50\n",
       "147      84\n",
       "148      83\n",
       "149       9\n",
       "\n",
       "[150 rows x 1 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>144</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 1 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 7
  },
  {
   "cell_type": "code",
   "id": "3dd71fa4-73b2-4bd1-aa2f-310943a5764e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.285844Z",
     "start_time": "2025-06-20T05:46:57.274558Z"
    }
   },
   "source": [
    "# 获取多列，花式索引\n",
    "df[['Python', 'Keras']]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     Python  Keras\n",
       "0       107     30\n",
       "1       144     32\n",
       "2        75     86\n",
       "3        12     92\n",
       "4        39     71\n",
       "..      ...    ...\n",
       "145      93     30\n",
       "146      50    131\n",
       "147      84    122\n",
       "148      83    104\n",
       "149       9     30\n",
       "\n",
       "[150 rows x 2 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>144</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>75</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>93</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>50</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>84</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>83</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>9</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 2 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "cell_type": "code",
   "id": "b66f09f6-e792-4825-8118-8c4f8e00b524",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.317200Z",
     "start_time": "2025-06-20T05:46:57.308412Z"
    }
   },
   "source": [
    "# 获取多列，切片\n",
    "df.iloc[:,::2]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     Python  Keras\n",
       "0       107     30\n",
       "1       144     32\n",
       "2        75     86\n",
       "3        12     92\n",
       "4        39     71\n",
       "..      ...    ...\n",
       "145      93     30\n",
       "146      50    131\n",
       "147      84    122\n",
       "148      83    104\n",
       "149       9     30\n",
       "\n",
       "[150 rows x 2 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>144</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>75</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>12</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>93</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>50</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>84</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>148</th>\n",
       "      <td>83</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>9</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>150 rows × 2 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "id": "f52d8a1a-e63b-4a1c-87a3-6b634877a2de",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.350523Z",
     "start_time": "2025-06-20T05:46:57.342531Z"
    }
   },
   "source": [
    "# 获取一行\n",
    "df.loc[[0]]   # 返回DataFrame\n",
    "# 注意：loc里面的0不是索引，而是行名，只是这里凑巧也是0"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "0     107         108     30"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>108</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 10
  },
  {
   "cell_type": "code",
   "id": "f45a3fde-3d75-407b-a446-1b3ba7778b10",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.390836Z",
     "start_time": "2025-06-20T05:46:57.383556Z"
    }
   },
   "source": [
    "# 获取一行\n",
    "df.loc[0]   # 返回Series"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        107\n",
       "Tensorflow    108\n",
       "Keras          30\n",
       "Name: 0, dtype: int32"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 11
  },
  {
   "cell_type": "code",
   "id": "48ae0ce6-573f-4fc3-ad3f-29710ce46d54",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.416487Z",
     "start_time": "2025-06-20T05:46:57.409710Z"
    }
   },
   "source": [
    "# 获取一行\n",
    "df.iloc[0]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        107\n",
       "Tensorflow    108\n",
       "Keras          30\n",
       "Name: 0, dtype: int32"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 12
  },
  {
   "cell_type": "code",
   "id": "0b5e3466-7efe-412f-a1e4-fb4ba75a168f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.445964Z",
     "start_time": "2025-06-20T05:46:57.437669Z"
    }
   },
   "source": [
    "# 获取一行\n",
    "df.iloc[[0]]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "0     107         108     30"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>108</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "cell_type": "code",
   "id": "aa16a154-c6fe-4c8b-b52e-22c165b1cdc3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.480745Z",
     "start_time": "2025-06-20T05:46:57.470720Z"
    }
   },
   "source": [
    "# 获取多行\n",
    "df.iloc[5: 11]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "5      101          40     70\n",
       "6       42          59     12\n",
       "7      141          34     13\n",
       "8       24          64    110\n",
       "9      125          25     31\n",
       "10      71         125     24"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>101</td>\n",
       "      <td>40</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>42</td>\n",
       "      <td>59</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>141</td>\n",
       "      <td>34</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>24</td>\n",
       "      <td>64</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>125</td>\n",
       "      <td>25</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>71</td>\n",
       "      <td>125</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "id": "f8ee58a6-bb00-401b-8259-c8d7648114cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.514659Z",
     "start_time": "2025-06-20T05:46:57.505240Z"
    }
   },
   "source": [
    "# 获取多行\n",
    "df.iloc[[0, 4, 9]]   # 获取第1行、第5行、第8行"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "0     107         108     30\n",
       "4      39         110     71\n",
       "9     125          25     31"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>107</td>\n",
       "      <td>108</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>39</td>\n",
       "      <td>110</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>125</td>\n",
       "      <td>25</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  },
  {
   "cell_type": "markdown",
   "id": "8a936a0e-4d0b-4572-954e-3c6d168fe6d3",
   "metadata": {},
   "source": [
    "## （2）标签选择"
   ]
  },
  {
   "cell_type": "code",
   "id": "fae91831-0534-457c-b45b-559d10d8df82",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.540809Z",
     "start_time": "2025-06-20T05:46:57.536252Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ],
   "outputs": [],
   "execution_count": 16
  },
  {
   "cell_type": "code",
   "id": "1c41fd0d-dc5c-454e-995c-987195f97c76",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.572411Z",
     "start_time": "2025-06-20T05:46:57.561180Z"
    }
   },
   "source": [
    "df2 = pd.DataFrame(\n",
    "    data=np.random.randint(0, 150, size=(10, 3)),   # 计算机科目考试成绩\n",
    "    index=list('ABCDEFGHIJ'),\n",
    "    columns=['Python','Tensorflow','Keras']\n",
    ")\n",
    "df2"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      99          40     83\n",
       "B     133          50     99\n",
       "C       5          94     73\n",
       "D     116         109    128\n",
       "E     114          24      0\n",
       "F      26          12    115\n",
       "G       7          44     46\n",
       "H     146          95    120\n",
       "I     102         105     17\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 17
  },
  {
   "cell_type": "code",
   "id": "edd466d6-e725-4d4f-848d-b1a4d927c879",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.601816Z",
     "start_time": "2025-06-20T05:46:57.593032Z"
    }
   },
   "source": [
    "# 选取指定行标签数据\n",
    "df2.loc[['A', 'C', 'D']]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      99          40     83\n",
       "C       5          94     73\n",
       "D     116         109    128"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 18
  },
  {
   "cell_type": "code",
   "id": "9f7a5a1b-2f7a-4323-aca8-5ffa89ff4513",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.638256Z",
     "start_time": "2025-06-20T05:46:57.624657Z"
    }
   },
   "source": [
    "# 根据行标签切片，选取指定列标签的数据\n",
    "df2.loc['A': 'E', ['Python', 'Keras']]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Keras\n",
       "A      99     83\n",
       "B     133     99\n",
       "C       5     73\n",
       "D     116    128\n",
       "E     114      0"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "cell_type": "code",
   "id": "68c7ea93-913c-4081-9d62-107323ee0548",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.678014Z",
     "start_time": "2025-06-20T05:46:57.668070Z"
    }
   },
   "source": [
    "# :默认保留所有行\n",
    "df2.loc[:, ['Keras', 'Tensorflow']]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Keras  Tensorflow\n",
       "A     83          40\n",
       "B     99          50\n",
       "C     73          94\n",
       "D    128         109\n",
       "E      0          24\n",
       "F    115          12\n",
       "G     46          44\n",
       "H    120          95\n",
       "I     17         105\n",
       "J    136          56"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>83</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>99</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>73</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>128</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>0</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>115</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>46</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>120</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>17</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>136</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 20
  },
  {
   "cell_type": "code",
   "id": "7cfa7cb9-8e0e-486f-bf54-03178adcdea7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.719714Z",
     "start_time": "2025-06-20T05:46:57.709194Z"
    }
   },
   "source": [
    "# 行切片从标签E开始每2个抽取一个，列标签进行切片\n",
    "df2.loc['E'::2, 'Python': 'Tensorflow']   # 如果你填写的是名字，那么左右都是闭区间，这个和索引不太一样"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow\n",
       "E     114          24\n",
       "G       7          44\n",
       "I     102         105"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 21
  },
  {
   "cell_type": "code",
   "id": "94779f52-5bde-4e44-95a5-9622546a92e3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.755757Z",
     "start_time": "2025-06-20T05:46:57.748433Z"
    }
   },
   "source": [
    "# 选取标量值\n",
    "df2.loc['A', 'Python']"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int32(99)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "cell_type": "markdown",
   "id": "3c15a235-6afd-49c5-b741-d104ac1c55bd",
   "metadata": {},
   "source": [
    "## （3）位置选择"
   ]
  },
  {
   "cell_type": "code",
   "id": "a1d191bb-3cfb-4c00-8611-f2e8436207bd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.793621Z",
     "start_time": "2025-06-20T05:46:57.781437Z"
    }
   },
   "source": [
    "data = np.random.randint(0, 150, size=(10, 3))\n",
    "index = list('ABCDEFGHIJ')\n",
    "columns = ['Python','Tensorflow','Keras']\n",
    "\n",
    "df3 = pd.DataFrame(\n",
    "    data=data,\n",
    "    index=index,\n",
    "    columns=columns\n",
    ")\n",
    "\n",
    "df3"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      88          71    110\n",
       "B     117          77      4\n",
       "C      17          42    100\n",
       "D     122         107     88\n",
       "E      24         145     79\n",
       "F     136          56     34\n",
       "G      18          79     44\n",
       "H      71         138     41\n",
       "I      27          33    145\n",
       "J      66          55     88"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>88</td>\n",
       "      <td>71</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>117</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>17</td>\n",
       "      <td>42</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>122</td>\n",
       "      <td>107</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>24</td>\n",
       "      <td>145</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>136</td>\n",
       "      <td>56</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>18</td>\n",
       "      <td>79</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>71</td>\n",
       "      <td>138</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>27</td>\n",
       "      <td>33</td>\n",
       "      <td>145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>66</td>\n",
       "      <td>55</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  },
  {
   "cell_type": "code",
   "id": "de26662c-4b71-45cd-a715-648f278030e8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.847227Z",
     "start_time": "2025-06-20T05:46:57.838617Z"
    }
   },
   "source": [
    "# 用整数位置选择\n",
    "df.iloc[4]  # 返回第5行数据，Series对象"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python         39\n",
       "Tensorflow    110\n",
       "Keras          71\n",
       "Name: 4, dtype: int32"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "cell_type": "code",
   "id": "b21f6dc0-1990-4826-8b28-e6c9de2f2def",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.900508Z",
     "start_time": "2025-06-20T05:46:57.891767Z"
    }
   },
   "source": [
    "# 用整数切片\n",
    "df3.iloc[:5, ::2]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Keras\n",
       "A      88    110\n",
       "B     117      4\n",
       "C      17    100\n",
       "D     122     88\n",
       "E      24     79"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>88</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>117</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>17</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>122</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>24</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 25
  },
  {
   "cell_type": "code",
   "id": "86e2490a-17d2-41e1-8510-60aef151eadb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.941704Z",
     "start_time": "2025-06-20T05:46:57.929935Z"
    }
   },
   "source": [
    "# 数组列表按位置切片\n",
    "df3.iloc[[1, 3], [0, 2]]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Keras\n",
       "B     117      4\n",
       "D     122     88"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>117</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>122</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 26
  },
  {
   "cell_type": "code",
   "id": "9dcdf61d-fc1e-489d-831a-cea5367024a4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:57.978654Z",
     "start_time": "2025-06-20T05:46:57.967914Z"
    }
   },
   "source": [
    "# 行切片\n",
    "df3.iloc[1: 3]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "B     117          77      4\n",
       "C      17          42    100"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>117</td>\n",
       "      <td>77</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>17</td>\n",
       "      <td>42</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  },
  {
   "cell_type": "code",
   "id": "651ba00c-1d58-4e7e-bb15-9ca25b110455",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.026389Z",
     "start_time": "2025-06-20T05:46:58.016013Z"
    }
   },
   "source": [
    "# 列切片\n",
    "df3.iloc[:, :2]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow\n",
       "A      88          71\n",
       "B     117          77\n",
       "C      17          42\n",
       "D     122         107\n",
       "E      24         145\n",
       "F     136          56\n",
       "G      18          79\n",
       "H      71         138\n",
       "I      27          33\n",
       "J      66          55"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>88</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>117</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>17</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>122</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>24</td>\n",
       "      <td>145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>136</td>\n",
       "      <td>56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>18</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>71</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>27</td>\n",
       "      <td>33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>66</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 28
  },
  {
   "cell_type": "code",
   "id": "04ceb099-18a9-4dce-be58-ede8d4392b32",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.062976Z",
     "start_time": "2025-06-20T05:46:58.056188Z"
    }
   },
   "source": [
    "# 选取某一个具体标量值\n",
    "df3.iloc[0, 2]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.int32(110)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 29
  },
  {
   "cell_type": "markdown",
   "id": "514be9da-40ac-45b4-95ee-cac6c5b7f788",
   "metadata": {},
   "source": [
    "## （4）布尔索引"
   ]
  },
  {
   "cell_type": "code",
   "id": "b52b8021-79bf-42e3-b5c6-d73628d4c1be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.093311Z",
     "start_time": "2025-06-20T05:46:58.082334Z"
    }
   },
   "source": [
    "# 深拷贝一个df\n",
    "df4 = df2.copy()\n",
    "df4\n",
    "# 在Pandas中，view()才是浅拷贝，copy()直接是深拷贝\n",
    "# 在Python中，copy()是浅拷贝，deepcopy()是深拷贝"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      99          40     83\n",
       "B     133          50     99\n",
       "C       5          94     73\n",
       "D     116         109    128\n",
       "E     114          24      0\n",
       "F      26          12    115\n",
       "G       7          44     46\n",
       "H     146          95    120\n",
       "I     102         105     17\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 30
  },
  {
   "cell_type": "code",
   "id": "bb0de5af-6388-40bf-a3b5-02c9c86d14be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.129186Z",
     "start_time": "2025-06-20T05:46:58.117015Z"
    }
   },
   "source": [
    "df4.iloc[0] = np.random.randint(0, 150, size=(1, 3))\n",
    "df4"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      95          46    146\n",
       "B     133          50     99\n",
       "C       5          94     73\n",
       "D     116         109    128\n",
       "E     114          24      0\n",
       "F      26          12    115\n",
       "G       7          44     46\n",
       "H     146          95    120\n",
       "I     102         105     17\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>95</td>\n",
       "      <td>46</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 31
  },
  {
   "cell_type": "code",
   "id": "d2b8752e-bd9b-43d9-9256-3cb246a2cf64",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.154572Z",
     "start_time": "2025-06-20T05:46:58.146861Z"
    }
   },
   "source": [
    "cond1 = df4.Python > 100\n",
    "cond1"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    False\n",
       "B     True\n",
       "C    False\n",
       "D     True\n",
       "E     True\n",
       "F    False\n",
       "G    False\n",
       "H     True\n",
       "I     True\n",
       "J     True\n",
       "Name: Python, dtype: bool"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 32
  },
  {
   "cell_type": "code",
   "id": "2e6dde01-d1e4-4223-88ec-0ae652deb077",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.186792Z",
     "start_time": "2025-06-20T05:46:58.176553Z"
    }
   },
   "source": [
    "df4[cond1]"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "B     133          50     99\n",
       "D     116         109    128\n",
       "E     114          24      0\n",
       "H     146          95    120\n",
       "I     102         105     17\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 33
  },
  {
   "cell_type": "code",
   "id": "c1654307-4eab-4ed1-95be-0c452c5693da",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.217797Z",
     "start_time": "2025-06-20T05:46:58.208977Z"
    }
   },
   "source": [
    "cond2 = (df4.Python > 50) & (df4['Keras'] > 50)\n",
    "cond2"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B     True\n",
       "C    False\n",
       "D     True\n",
       "E    False\n",
       "F    False\n",
       "G    False\n",
       "H     True\n",
       "I    False\n",
       "J     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 34
  },
  {
   "cell_type": "code",
   "id": "390d6659-ff84-479e-8286-201ac5c62ac9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.252890Z",
     "start_time": "2025-06-20T05:46:58.241150Z"
    }
   },
   "source": [
    "df4[cond2]   # 返回Python和Keras同时大于50分的 "
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      95          46    146\n",
       "B     133          50     99\n",
       "D     116         109    128\n",
       "H     146          95    120\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>95</td>\n",
       "      <td>46</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 35
  },
  {
   "cell_type": "markdown",
   "id": "59724d82-f9a8-4f39-9808-d0fe19d0c557",
   "metadata": {},
   "source": [
    "## （5）赋值操作"
   ]
  },
  {
   "cell_type": "code",
   "id": "41272f64-5236-4b90-b697-9aa84cb16ac4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.293179Z",
     "start_time": "2025-06-20T05:46:58.282136Z"
    }
   },
   "source": [
    "df5 = df2.copy()\n",
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      99          40     83\n",
       "B     133          50     99\n",
       "C       5          94     73\n",
       "D     116         109    128\n",
       "E     114          24      0\n",
       "F      26          12    115\n",
       "G       7          44     46\n",
       "H     146          95    120\n",
       "I     102         105     17\n",
       "J     132          56    136"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 36
  },
  {
   "cell_type": "code",
   "id": "631e8b37-ff44-48ae-8bdb-94897b32b094",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.314454Z",
     "start_time": "2025-06-20T05:46:58.306197Z"
    }
   },
   "source": [
    "# 单独创建一个Series，添加到df5中\n",
    "s = pd.Series(\n",
    "    data=np.random.randint(0, 150, size=(10,)),\n",
    "    # name='Pytorch',\n",
    "    index=list('ABCDEFGHIJ')\n",
    ")\n",
    "s   # 这个s要注意，index 得和df5匹配才能插入"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    136\n",
       "B     45\n",
       "C     42\n",
       "D     14\n",
       "E     27\n",
       "F     96\n",
       "G    110\n",
       "H    104\n",
       "I     11\n",
       "J     23\n",
       "dtype: int32"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 37
  },
  {
   "cell_type": "code",
   "id": "0fe99cdc-e595-47d3-a059-21c965bea288",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.340048Z",
     "start_time": "2025-06-20T05:46:58.329204Z"
    }
   },
   "source": [
    "# 将s添加到\n",
    "df5['Pytorch'] = s\n",
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras  Pytorch\n",
       "A      99          40     83      136\n",
       "B     133          50     99       45\n",
       "C       5          94     73       42\n",
       "D     116         109    128       14\n",
       "E     114          24      0       27\n",
       "F      26          12    115       96\n",
       "G       7          44     46      110\n",
       "H     146          95    120      104\n",
       "I     102         105     17       11\n",
       "J     132          56    136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>128</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 38
  },
  {
   "cell_type": "code",
   "id": "be50e1e7-eac2-4d30-97fb-a11f76e65141",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.367783Z",
     "start_time": "2025-06-20T05:46:58.361308Z"
    }
   },
   "source": [
    "# 对标量赋值\n",
    "df5.iloc[3, 2] = 0"
   ],
   "outputs": [],
   "execution_count": 39
  },
  {
   "cell_type": "code",
   "id": "2b7f8306-72c6-4f64-9796-e5e2e53207f3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.388072Z",
     "start_time": "2025-06-20T05:46:58.378200Z"
    }
   },
   "source": [
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras  Pytorch\n",
       "A      99          40     83      136\n",
       "B     133          50     99       45\n",
       "C       5          94     73       42\n",
       "D     116         109      0       14\n",
       "E     114          24      0       27\n",
       "F      26          12    115       96\n",
       "G       7          44     46      110\n",
       "H     146          95    120      104\n",
       "I     102         105     17       11\n",
       "J     132          56    136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>99</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>133</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>109</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>114</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>26</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>7</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>146</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>102</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>132</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 40
  },
  {
   "cell_type": "code",
   "id": "7f22a434-0f20-4cc1-9648-7ffa3f4d04c6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.431779Z",
     "start_time": "2025-06-20T05:46:58.419342Z"
    }
   },
   "source": [
    "# 按numpy数组进行赋值\n",
    "df5.loc[:, 'Python'] = np.array([128]*10)\n",
    "df5"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\WangBing\\AppData\\Local\\Temp\\ipykernel_13396\\504936267.py:2: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '[128 128 128 128 128 128 128 128 128 128]' has dtype incompatible with int32, please explicitly cast to a compatible dtype first.\n",
      "  df5.loc[:, 'Python'] = np.array([128]*10)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras  Pytorch\n",
       "A     128          40     83      136\n",
       "B     128          50     99       45\n",
       "C     128          94     73       42\n",
       "D     128         109      0       14\n",
       "E     128          24      0       27\n",
       "F     128          12    115       96\n",
       "G     128          44     46      110\n",
       "H     128          95    120      104\n",
       "I     128         105     17       11\n",
       "J     128          56    136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>128</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>128</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>128</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>128</td>\n",
       "      <td>109</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>128</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>128</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>128</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>128</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>128</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>128</td>\n",
       "      <td>56</td>\n",
       "      <td>136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 41
  },
  {
   "cell_type": "code",
   "id": "a0ddf63a-9860-4ec7-947f-826964ab9de3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.457405Z",
     "start_time": "2025-06-20T05:46:58.449803Z"
    }
   },
   "source": [
    "# 按照条件进行赋值，大于等于128变成负数\n",
    "df5[df5 >= 128] = -df5"
   ],
   "outputs": [],
   "execution_count": 42
  },
  {
   "cell_type": "code",
   "id": "5002e824-0ac3-4e97-b07a-d556c37a1e11",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.485085Z",
     "start_time": "2025-06-20T05:46:58.476356Z"
    }
   },
   "source": [
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras  Pytorch\n",
       "A    -128          40     83     -136\n",
       "B    -128          50     99       45\n",
       "C    -128          94     73       42\n",
       "D    -128         109      0       14\n",
       "E    -128          24      0       27\n",
       "F    -128          12    115       96\n",
       "G    -128          44     46      110\n",
       "H    -128          95    120      104\n",
       "I    -128         105     17       11\n",
       "J    -128          56   -136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>-128</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>-136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-128</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-128</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-128</td>\n",
       "      <td>109</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-128</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-128</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>-128</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-128</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-128</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-128</td>\n",
       "      <td>56</td>\n",
       "      <td>-136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 43
  },
  {
   "cell_type": "code",
   "id": "d035b915-b15f-4ab0-9e36-6935a625451a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.502719Z",
     "start_time": "2025-06-20T05:46:58.497303Z"
    }
   },
   "source": [
    "# 在指定位置插入一列\n",
    "df5.insert(\n",
    "    loc=1, # 指定插入位置\n",
    "    column='xxx',   # 插入的列名叫 xxx\n",
    "    value=1024   # 插入的值\n",
    ")"
   ],
   "outputs": [],
   "execution_count": 44
  },
  {
   "cell_type": "code",
   "id": "b069081e-4a55-4cb2-9058-599df738e086",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.522748Z",
     "start_time": "2025-06-20T05:46:58.512675Z"
    }
   },
   "source": [
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python   xxx  Tensorflow  Keras  Pytorch\n",
       "A    -128  1024          40     83     -136\n",
       "B    -128  1024          50     99       45\n",
       "C    -128  1024          94     73       42\n",
       "D    -128  1024         109      0       14\n",
       "E    -128  1024          24      0       27\n",
       "F    -128  1024          12    115       96\n",
       "G    -128  1024          44     46      110\n",
       "H    -128  1024          95    120      104\n",
       "I    -128  1024         105     17       11\n",
       "J    -128  1024          56   -136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>xxx</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>-136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>109</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-128</td>\n",
       "      <td>1024</td>\n",
       "      <td>56</td>\n",
       "      <td>-136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 45
  },
  {
   "cell_type": "code",
   "id": "64e8b92e-f502-459d-97c1-3e010012c2b4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.539421Z",
     "start_time": "2025-06-20T05:46:58.534314Z"
    }
   },
   "source": [
    "#删除一列\n",
    "del df5['xxx']"
   ],
   "outputs": [],
   "execution_count": 46
  },
  {
   "cell_type": "code",
   "id": "6df86860-f891-4d11-ae44-3b06928efbfd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.577129Z",
     "start_time": "2025-06-20T05:46:58.567129Z"
    }
   },
   "source": [
    "df5"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   Python  Tensorflow  Keras  Pytorch\n",
       "A    -128          40     83     -136\n",
       "B    -128          50     99       45\n",
       "C    -128          94     73       42\n",
       "D    -128         109      0       14\n",
       "E    -128          24      0       27\n",
       "F    -128          12    115       96\n",
       "G    -128          44     46      110\n",
       "H    -128          95    120      104\n",
       "I    -128         105     17       11\n",
       "J    -128          56   -136       23"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Pytorch</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>-128</td>\n",
       "      <td>40</td>\n",
       "      <td>83</td>\n",
       "      <td>-136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-128</td>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>-128</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-128</td>\n",
       "      <td>109</td>\n",
       "      <td>0</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>-128</td>\n",
       "      <td>24</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-128</td>\n",
       "      <td>12</td>\n",
       "      <td>115</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>-128</td>\n",
       "      <td>44</td>\n",
       "      <td>46</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>-128</td>\n",
       "      <td>95</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>-128</td>\n",
       "      <td>105</td>\n",
       "      <td>17</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>-128</td>\n",
       "      <td>56</td>\n",
       "      <td>-136</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 47
  },
  {
   "cell_type": "code",
   "id": "4025fbed-1ec5-4181-a551-96af7fbf3d06",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-20T05:46:58.657209Z",
     "start_time": "2025-06-20T05:46:58.654042Z"
    }
   },
   "source": [],
   "outputs": [],
   "execution_count": null
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
